﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using WPF_CAD.Common;
using WPF_CAD.Model;
using System.Windows.Controls;

namespace WPF_CAD.Strategy
{
    public class SelectionToolStrategy : StrategyBase
    {
        public SelectionToolStrategy(IFigure figure)
            : base(figure)
        {
        }

        public override IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            throw new NotImplementedException();
        }

        public override IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            foreach (var figure in figures)
                try
                {
                    if (figure.PointsCollection.Single(p => p.X == point.X && p.Y == point.Y) != null)
                        Figure = figure;
                }
                catch (InvalidOperationException)
                {}

            if (Figure.DrawStatus == DrawStatus.Completed) FigureDrawer.DrawFigure(canvas, Figure, Colors.Red);

            return Figure;
        }
    }
}
